#!/bin/sh

trim() { head -n "200"; }
case "$1" in
  *.asc) cat "$1" | trim;;
  *.tar.*) tar tf "$1" | trim;;
  *.zip) unzip -l "$1" | trim;;
  *.rar) unrar l "$1" | trim;;
  *.7z) 7z l "$1" | trim;;
  *.pdf) pdftotext "$1" - | trim;;
  *.epub) epub2txt "$1" - | trim;;
  *.torrent) transmission-show "$1" | trim;;
  *.html|*.xhtml|*.htm|*.mthml) elinks -dump $1 || lynx -dump "$1" || w3m -dump "$1" || links -dump "$1";;
  *)
    case $(file --mime-type -Lb "$1") in
      #video/*|audio/*) mediainfo "$1" | trim | sed 's/  \+:/: /;';;
      #image/*) img2txt "$1";;
      *) highlight -O ansi "$1" || cat "$1";;
    esac
  ;;
esac
